﻿// JScript File

        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
            
            var rowCount = table.rows.length;
            var iteration = rowCount;
            var row = table.insertRow(rowCount);    
                   
//            var cell1 = row.insertCell(0);
//            var element1 = document.createElement("input");
//            element1.type = "checkbox";
//            cell1.appendChild(element1); 
            
            var cell2 = row.insertCell(0);
            var element2 = document.createElement("input");
            element2.type = "text";
            cell2.appendChild(element2);            
            element2.id = 'title' + iteration;
            element2.name = 'title' + iteration;
            //element2.onChange= function(){alert("It WORKED!")};
            element2.setAttribute('onChange',"validateTitle('dataTable')");
 
            var cell3 = row.insertCell(1);
            var element3 = document.createElement("input");
            element3.type = "text";
            cell3.appendChild(element3);
            element3.id = 'name' + iteration;
            element3.name = 'name' + iteration;
            //element3.onChange= function(){alert("It WORKED!")};
            element3.setAttribute('onChange',"validateName('dataTable')");
 
        };
        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length; 
            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                //var chkbox = row.cells[0].childNodes[0];
                //if(null != chkbox && true == chkbox.checked) {
                if(rowCount == i+1){
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                } 
               
            }
            
            }catch(e) {
                alert(e);
            }
            validateRow(tableID);
        };
    function validateRow(tableID)
    {
        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;             
        var txtTitle = document.getElementById('<%=this.txt.ClientID%>');
        var txtName = document.getElementById('<%=this.txt1.ClientID%>');
        txtName.value ='';
        txtTitle.value ='';
        for(var i=0; i<=rowCount; i++) 
        {            
            var row = table.rows[i];                
            var title = document.getElementById('title' + i).value;                
            var Name = document.getElementById('name' + i).value; 
               txtTitle.value += title +',';
               txtName.value += Name +',';              
        } 
    };
    
    function validateTitle(tableID)
    {
        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;             
        var txtTitle = document.getElementById('<%=this.txt.ClientID%>');
        txtTitle.value='';
        for(var i=0; i<=rowCount; i++) 
        {            
            var row = table.rows[i];                
            var title = document.getElementById('title' + i).value;
               txtTitle.value += title +',';               
        } 
    };
    function validateName(tableID)
    {
        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;             
        var txtName = document.getElementById('<%=this.txt1.ClientID%>');  
        txtName.value ='';      
        for(var i=0; i<=rowCount; i++) 
        {            
            var row = table.rows[i];                
            var Name = document.getElementById('name' + i).value; 
               txtName.value += Name +',';              
        } 
    };   